function modSelect(select, val) {
  select.innerHTML = "";
  for (const item in val) {
    const node = document.createElement("option");
    if (typeof val[item] === "string") {
      node.value = val[item];
    } else {
      node.value = item;
    }
    node.innerText = item;
    select.appendChild(node);
  }
  select.dispatchEvent(new Event("change"));
}
tts
  .getSpeakers()
  .catch(alert)
  .then((val) => {
    window.speakers = val;
    const select = document.querySelector("select#type");
    select.addEventListener("change", (e) => {
      const type = e.target.value;
      const select = document.querySelector("select#cj");
      select.addEventListener("change", (e) => {
        const select = document.querySelector("select#speaker");
        modSelect(select, val[type][e.target.value]);
      });
      modSelect(select, val[type]);
    });
    modSelect(select, val);
  });
